<template>
  <div class="div-rolling-layers" v-if="isVisible">
    <el-row class="div-rolling-container">
      <el-col :span="12">
        <el-row>
          <el-col :span="8" class="text-altras">
            <span>左侧屏幕</span>
          </el-col>
          <el-col :span="16">
            <el-select
              size="mini"
              class="el-select-rolling"
              v-model="leftSelectLayer"
              placeholder="请选择左侧图层"
              @change="leftSelectChange"
            >
              <el-option
                v-for="imgLayer in imgLayers"
                :key="imgLayer._id"
                :value="imgLayer._id"
                :label="imgLayer.name"
              ></el-option>
            </el-select>
          </el-col>
        </el-row>

      </el-col>
      <el-col :span="12">
        <el-row>
          <el-col :span="16">
            <el-select
              size="mini"
              class="el-select-rolling"
              v-model="rightSelectLayer"
              placeholder="请选择右侧图层"
              @change="rightSelectChange"
            >
              <el-option
                v-for="imgLayer in imgLayers"
                :key="imgLayer._id"
                :value="imgLayer._id"
                :label="imgLayer.name"
              ></el-option>
            </el-select>
          </el-col>
          <el-col :span="8" class="text-altras">
            <span>右侧屏幕</span>
          </el-col>
        </el-row>

      </el-col>

    </el-row>
  </div>
</template>

<script>
  import {list} from '@/api/yxwh/ygjc';

  export default {
    name: "index",
    data: function () {
      return {leftSelectLayer: undefined, rightSelectLayer: undefined, imgLayers: []}
    },
    props: {
      isVisible: {
        type: Boolean,
        default: false
      }
    },
    methods: {
      /**
       * 左侧图层选择
       * @param $event
       */
      leftSelectChange($event) {
        this.imgLayers.forEach(layer => {
          if (layer._id === $event) {   //TODO 超图发布的服务
            this.$emit('onRsLayerSelected', 'left', layer);
          }
        })

      },
      /**
       * 右侧图层选择
       * @param $event
       */
      rightSelectChange($event) {
        this.imgLayers.forEach(layer => {
          if (layer._id === $event) {
            this.$emit('onRsLayerSelected', 'right', layer);
          }
        })
      },
      /**
       * 获取默认第一个图层
       */
      getTopDefaultImageLayer() {
        return this.imgLayers[0];
      },
      emptySelector() {
        this.leftSelectLayer = undefined,
          this.rightSelectLayer = undefined
      }

    },
    mounted() {
      list().then(res => {
        this.imgLayers = res.data;
      })
    },
    watch: {
      isVisible: function (n, o) {
        this.leftSelectLayer = undefined;
        this.rightSelectLayer = undefined;
      }
    }

  }
</script>

<style>

   
  .div-rolling-layers {
    display: block;
    position: relative;
  }

   


  .div-rolling-layers .div-rolling-container {
    position: absolute;
    display: flex;
    top: 60px;
    left: 0;
    right: 0;
    margin: 0 auto;
    z-index: 3;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.3);
    color:#fff;
    width: 598px;
    align-items: center;
    border-radius: 5px;
    border: 2px solid #398f8699;
    padding: 2px;
  }

  .div-rolling-layers .text-altras {
    position: relative;
    text-align: center;
    line-height: 28px;
  }

</style>
